package cloudPayAdmin.admin.service.traffic;

import cloudPayAdmin.admin.dbapp.entity.traffic.TTrafficMessage;
import cloudPayAdmin.admin.dbapp.repo.traffic.TrafficMessageRepo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class TrafficMessageService {

    @Autowired
    TrafficMessageRepo trafficMessageRepo;

    @Transactional(readOnly = true)
    public List<TTrafficMessage> findByDetectorId(Long detectorId, Boolean enabled, String startTimeBegin, String startTimeEnd) {
        if (!StringUtils.isEmpty(startTimeBegin) && !StringUtils.isEmpty(startTimeEnd)) {
            return trafficMessageRepo.findByDetectorIdAndEnableAndStartTimeBetween(detectorId, enabled, startTimeBegin, startTimeEnd);
        } else {
            return trafficMessageRepo.findByDetectorIdAndEnable(detectorId, enabled);

        }
    }
}
